﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Entities</title>
<link type="text/css" rel="stylesheet" href="bootstrap.min.css" />
</head>

<body>

<ul>
	<li><a href="#DocConfigureAbp">Configuring ASP.NET Boilerplate</a></li>
	<li><a href="#DocConfigureModules">Configuring Modules</a></li>
	<li><a href="#DocCreateModuleConfig">Creating configuration for a module</a></li>
</ul>


<p>ASP.NET Boilerplate provides an infrastructure to configure it and
<a href="/Pages/Documents/Module-System">modules</a> on startup.</p>

<h3 id="DocConfigureAbp">Configuring ASP.NET Boilerplate</h3>
<p>Configuring ASP.NET Boilerplate is made on <strong>PreInitialize</strong> event of your 
module. Example configuration:</p>
<pre lang="cs">public class SimpleTaskSystemModule : AbpModule
{
    public override void PreInitialize()
    {
        //Add languages for your application
        Configuration.Localization.Languages.Add(new LanguageInfo(&quot;en&quot;, &quot;English&quot;, &quot;famfamfam-flag-england&quot;, true));
        Configuration.Localization.Languages.Add(new LanguageInfo(&quot;tr&quot;, &quot;T&#252;rk&#231;e&quot;, &quot;famfamfam-flag-tr&quot;));

        //Add a localization source
        Configuration.Localization.Sources.Add(
            new XmlLocalizationSource(
                &quot;SimpleTaskSystem&quot;,
                HttpContext.Current.Server.MapPath(&quot;~/Localization/SimpleTaskSystem&quot;)
                )
            );

        //Configure navigation/menu
        Configuration.Navigation.Providers.Add&lt;SimpleTaskSystemNavigationProvider&gt;();
    }

    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
    }
}</pre>
<p>ASP.NET Boilerplate is designed <strong>modularity</strong> in mind. Different modules can 
configure ASP.NET Boilerplate. For example, different modules can add navigation 
provider to add their own menu items to the main menu. See
<a href="/Pages/Documents/Localization">localization</a> and
<a href="/Pages/Documents/Navigation">navigation</a> documents for details.</p>

<h3 id="DocConfigureModules">Configuring Modules</h3>

<p>Beside framework's own startup configuration, a module can extend 
<strong>IAbpModuleConfigurations</strong> interface to provide configuration points for the module. 
Example:</p>
<pre>...
using Abp.Web.Configuration;
...
public override void PreInitialize() 
{
    Configuration.Modules.AbpWeb().SendAllExceptionsToClients = true;
}
...</pre>
<p>In this example, we configured AbpWeb module to send all exceptions to 
clients.</p>
<p>Not every module should define this type of configuration. It's generally needed when a 
module will be re-usable in different applications and needs to be configured on 
startup.</p>
<h3 id="DocCreateModuleConfig">Creating configuration for a module</h3>
<p>Assume that we have a module named MyModule and it has some configuration 
properties. First, we create a class for these cofigurable properties:</p>
<pre lang="cs">public class MyModuleConfig
{
    public bool SampleConfig1 { get; set; }

    public string SampleConfig2 { get; set; }
}</pre>
<p>Then we register this class to DI on PreInitialize event of MyModule (Thus, 
it will be injectable):</p>
<pre lang="cs">IocManager.Register&lt;MyModuleConfig&gt;();</pre>
<p>Finally, we create an extension method to IModuleConfigurations to get a 
reference to the MyConfig:</p>
<pre lang="cs">public static class MyModuleConfigurationExtensions
{
    public static MyModuleConfig MyModule(this IModuleConfigurations moduleConfigurations)
    {
        return moduleConfigurations.AbpConfiguration
            .GetOrCreate(&quot;MyModuleConfig&quot;,
                () =&gt; moduleConfigurations.AbpConfiguration.IocManager.Resolve&lt;MyModuleConfig&gt;()
            );
    }
}</pre>
<p>Now, other modules can configure this module on startup (on PreInitialize 
event of the module which need to configure MyModule):</p>
<pre lang="cs">Configuration.Modules.MyModule().SampleConfig1 = false;
Configuration.Modules.MyModule().SampleConfig2 = &quot;test&quot;;</pre>
<p>At some point, MyModule needs to this configuration. You can inject 
MyModuleConfig and use configured values. Example:</p>
<pre lang="cs">public class MyService : ITransientDependency
{
    private readonly MyModuleConfig _configuration;

    public MyService(MyModuleConfig configuration)
    {
        _configuration = configuration;
    }

    public void DoIt()
    {
        if (_configuration.SampleConfig2 == &quot;test&quot;)
        {
            //...
        }
    }
}</pre>

<p>Thus, modules can create central configuration points in ASP.NET Boilerplate 
system.</p>

</body>

</html>
